package com.example.mybank.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybank.entity.Orders;
import com.example.mybank.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    OrdersMapper ordersMapper;

    // 管理员：获取所有订单
    @GetMapping("/all")
    public List<Orders> getAll(){
        return ordersMapper.selectList(null);
    }

    // 用户：查看某个账户的的订单
    @GetMapping("/account/{accountID}")
    public List<Orders> getByAccount(@PathVariable("accountID") int accountID){
        QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account",accountID);
        return ordersMapper.selectList(queryWrapper);
    }

    // 用户：查看自己的订单
    @GetMapping("/users/{userID}")
    public List<Orders> getByUsers(@PathVariable("userID") int usersID){
        QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("users",usersID);
        return ordersMapper.selectList(queryWrapper);
    }



}
